
package com.scs.application.modules.order.service;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.scs.application.core.model.CommonResult;
import com.scs.application.core.service.IBaseService;
import com.scs.application.modules.order.dto.CloseOrderDto;
import com.scs.application.modules.order.dto.OrderDTO;
import com.scs.application.modules.order.dto.PushThirdOrderStatusDTO;
import com.scs.application.modules.order.entity.PurchaseOrder;
import com.scs.application.modules.order.request.PurchaseOrderQueryRequest;
import com.scs.application.modules.order.request.ScanQrcodeRequest;
import com.scs.application.modules.order.vo.ExcelPurchaseOrderVO;
import com.scs.application.modules.thirdparty.erp.request.CloseOrderRequest;
import com.scs.application.modules.thirdparty.erp.request.OrderConfirmRequest;
import com.scs.application.modules.thirdparty.erp.request.OrderRequest;
import com.scs.application.modules.thirdparty.erp.request.OrderStatusRequest;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.Date;
import java.util.List;

/**
 * 采购订单 service 接口
 *
 */
public interface PurchaseOrderService extends IBaseService<PurchaseOrder> {

    List<PurchaseOrder> list(PurchaseOrderQueryRequest request);


    IPage<PurchaseOrder> page(PurchaseOrderQueryRequest request);

    IPage<ExcelPurchaseOrderVO> pageExcel(PurchaseOrderQueryRequest request);

    List<ExcelPurchaseOrderVO> listExcel(PurchaseOrderQueryRequest request);

    /**
     * 添加订单
     *
     * @param entity
     * @return
     */
    PurchaseOrder add(PurchaseOrder entity);

    PurchaseOrder addForSp(PurchaseOrder entity);

    /**
     * 采购订单-提交 将订单状态 制单0改为待审核1
     *
     * @param id
     */
    void submitOrder(String id);

    /**
     * 待审核订单-通过 将订单状态 待审核1改为供应商待确认2
     *
     * @param id
     */
    void passOrder(String id);

    /**
     * 取消提交的采购订单， 将待审核状态 1 改为 待提交状态 0
     *
     * @param id
     */
    void cancelOrder(String id);

    /**
     * 待审核订单-关闭 将订单状态 改为完成9 关闭状态改为关闭1
     *
     * @param dto
     */
    void closeOrder(CloseOrderDto dto);

    /**
     * 供应商待确认订单
     *
     * @param request
     * @return
     */
    IPage<PurchaseOrder> pageForSupplier(PurchaseOrderQueryRequest request);

    /**
     * @param request 查询未发货和部分发货订单
     * @return: com.baomidou.mybatisplus.core.metadata.IPage<com.scs.application.modules.order.entity.PurchaseOrder>
     */
    IPage<PurchaseOrder> pageForDelivery(PurchaseOrderQueryRequest request);

    IPage<PurchaseOrder> pageForSupplierAdd(PurchaseOrderQueryRequest request);

    /**
     * 供应商待确认订单-可供货 将供应商确认状态 待确认0改为确认不可供货2
     *
     * @param dto
     */
    void disable(CloseOrderDto dto);

    /**
     * 接收院方接口订单信息
     *
     * @param orderDTOS
     */
    void batchSaveForDTO(List<OrderDTO> orderDTOS, Boolean isTxt);

    /**
     * 院方订单状态同步
     *
     * @param beginDate
     * @return
     */
    List<PurchaseOrder> listForHospital(List<String> codes, Date beginDate);

    // 今日已发货订单
    int orderSendCount(PurchaseOrderQueryRequest request);

    //今日已发货金额
    PurchaseOrder selectDeliveryCount(PurchaseOrderQueryRequest request);

    //今日可供货订单
    int availableOrdersCount(PurchaseOrderQueryRequest request);

    //今日已发货订单
    int deliveryCount(PurchaseOrderQueryRequest request);

    //今日已完成订单
    int finishedCount(PurchaseOrderQueryRequest request);

    //今日已完成订单金额
    PurchaseOrder finishedAmountCount(PurchaseOrderQueryRequest request);

    //发货状态
    //List<PurchaseOrder> orderSendStatus();

    /*  // 今日已接收订单
      int orderSendCountSupplier(PurchaseOrderQueryRequest request);
      //今日已发货金额
      PurchaseOrder selectUndeliveryCountSupplier(PurchaseOrderQueryRequest request);*/
    //可供货订单
    int availableOrdersCountSupplier(PurchaseOrderQueryRequest request);

    //今日已发货订单
    int deliveryCountSupplier(PurchaseOrderQueryRequest request);

    //今日已完成订单
    int finishedCountSupplier(PurchaseOrderQueryRequest request);

    //今日已完成订单金额
    PurchaseOrder finishedAmountCountSupplier(PurchaseOrderQueryRequest request);

    /**
     * ERP 获取订单
     * @param orderDate
     * @param codes
     * @return
     */
    CommonResult getOrdersERP(String hospitalId, String orderDate, String[] codes);

    CommonResult callStatus(List<OrderStatusRequest> list);

    void pushOrderToThirdPlatForm(List<OrderDTO> dtos);

    void pushOrderStatusToThirdPlatForm(PushThirdOrderStatusDTO dto);

    JSONObject loadPoQrcode(ScanQrcodeRequest request);

    CommonResult closeOrderERP(@RequestBody CloseOrderRequest request);

    CommonResult orderInfoDownLoad(OrderRequest request);

    CommonResult orderDownloadConfirm(OrderConfirmRequest request);

    @Transactional(rollbackFor = Exception.class)
    void saveAndSend(PurchaseOrder entity,Boolean isSave);
}
